﻿using duia.Canteenpay.Domain;
using duia.Canteenpay.Domain.DomainObject;
using duia.Canteenpay.Domain.IRepository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace duia.Canteenpay.Repository.Repository
{
    /// <summary>
    /// 订单分类仓储实现
    /// </summary>
    public class DishesCategoryRepository : BaseRepository<DishesCategory>, IDishesCategoryRepository
    {
        

        public DishesCategoryRepository(AppUnitOfWork appUnitOfWork) : base(appUnitOfWork)
        {
        }


        public override async Task<DishesCategory> Find(Expression<Func<DishesCategory, bool>> wherExpression)
        {
            var firstOrDefault = await base.Entity.Where(wherExpression).FirstOrDefaultAsync();
            if (firstOrDefault != null)
            {
                await _context.Entry(firstOrDefault).Collection(x => x.Dishes).LoadAsync();
            }
            return firstOrDefault;
        }

    }
}
